package com.xmut.mall.member.controller;

import com.xmut.mall.member.annotation.CheckJwt;
import com.xmut.mall.member.entity.MemberCartEntity;
import com.xmut.mall.member.entity.MemberCouponEntity;
import com.xmut.mall.member.searchparam.UserCentCouponSearchParam;
import com.xmut.mall.member.utils.RespBean;
import com.xmut.mall.member.vo.PageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xmut.mall.member.service.MemberCouponService;

import java.util.List;
import java.util.Map;


/**
 *
 *
 * @author 1912120131suntingxing
 * @email 1192081604@qq.com
 * @date 2023-02-02 06:24:39
 */
@RestController
@RequestMapping("member/membercoupon")
public class MemberCouponController {
    @Autowired
    private MemberCouponService memberCouponService;

    /**
     * 根据传入的购物车项获取当前用户结算时可用的优惠券
     * @param list
     * @return
     */
    @CheckJwt
    @PostMapping("/getUserAllCanUseCouponByCART")
    public RespBean getUserAllCanUseCouponByCART(@RequestBody List<MemberCartEntity> list){
        List<MemberCouponEntity> memberCouponEntityList = memberCouponService.getUserAllCanUseCouponByCART(list);
        return RespBean.success("获取成功",memberCouponEntityList);
    }

    /**
     * 获取用户领取的优惠券中 全部的 可以使用后的优惠券
     * @param params
     * @return
     */
    @CheckJwt
    @PostMapping("/getUserAllCanUseCoupon")
    public RespBean getUserAllCanUseCoupon(@RequestBody Map<String,Object> params){
        return memberCouponService.getUserAllCanUseCoupon(params);
    }

    /**
     * 获取用户中心的优惠券分页数据
     * @param param
     * @return
     */
    @CheckJwt
    @PostMapping("/gerUserCenterCouponPage")
    public RespBean gerUserCenterCouponPage(@RequestBody UserCentCouponSearchParam param){
        System.out.println("拿到的param:"+param);
        PageVO vo = new PageVO();
        BeanUtils.copyProperties(param,vo);
        return memberCouponService.gerUserCenterCouponPage(vo,param);
    }

    /**
     * 用户领取优惠券
     * @param params
     * @return
     */
    @PostMapping("/userReceiveCoupon")
    public RespBean userReceiveCoupon(@RequestBody Map<String,Object> params){
        return memberCouponService.userReceiveCoupon(params);
    }
}
